package com.dgut.util;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String loginName = (String) session.getAttribute("loginName");
        response.setContentType("text/html;charset=utf-8");
        if (loginName == null || loginName.equals("")){
            //response.sendRedirect(request.getContextPath()+"/login.html");
            return false;
        }
        return true;
    }
}
